<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue计算器</title>
</head>
<body>
<div>
    <input type="text" placeholder="请输入一个数字" v-model="input1">
    <input type="text" placeholder="请输入一个数字" v-model="input2">
    <input type="button" value="加" @click="f(1)">
    <input type="button" value="减" @click="f(2)">
    <input type="button" value="乘" @click="f(3)">
    <input type="button" value="除" @click="f(4)">
    <p>结果：<span v-text="result"></span></p>
</div>

<script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/2.6.14/vue.js"></script>
<script>
    let v = new Vue({
        el: "div",
        data: {
            input1: "",
            input2: "",
            result: "",
        },
        methods: {
            f: function (x) {
                if (isNaN(v.input1)||isNaN(v.input2)){
                    v.result = "不是一个数字，重新输入";
                    return;
                }
                switch (x) {
                    case 1:
                        v.result = v.input1 * 1 + v.input2 * 1;
                        break;
                    case 2:
                        v.result = v.input1 - v.input2;
                        break;
                    case 3:
                        v.result = v.input1 * v.input2;
                        break;
                    case 4:
                        v.result = v.input1 / v.input2;
                }

            }
        }
    });

</script>

</body>
</html>